package main.test.SparkAPI.Baics.classApi

abstract class RobotUDF(private var name:String) {
  def getName: String = name
  def setName(newName:String): Unit =   this.name = newName
  def welcome: String

}



object RobotUDF{
  /**
   *
   * @param r1
   * @param r2
   * @return if r1 and r2 are both not null, it returns true, otherwise false.
   */
  def checkNulls(r1:RobotUDF,r2:RobotUDF): Boolean = r1!=null && r2!=null

  /**
   *
   * @param r1
   * @param r2
   * @return if robot r1 say more words than r2, it return r1, otherwise r2 under the condition
   *         that r1 and r2 are both not null. If condition cant be
   *         satisfied, it will raise NullPointerException.
   */
  def mostTalktive(r1: RobotUDF, r2: RobotUDF):RobotUDF = {
//    if (r1==null  || r2==null) throw new NullPointerException("not allowed null RobotUDF class") else {
    if ( r1!=null && r2!=null){
      val r1Size = r1.welcome.length
      val r2Size = r2.welcome.length
      if (r1Size>=r2Size) r1 else r2
    } else throw new NullPointerException("not allowed null RobotUDF class")

  }
}